package com.tarena.seata.order.service;

import com.tarena.seata.api.CartApi;
import com.tarena.seata.api.StockApi;
import com.tarena.seata.order.mapper.OrderMapper;
import com.tarena.seata.order.pojo.OrderPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private StockApi stockApi;
    @Autowired
    private CartApi cartApi;
    @Transactional(rollbackFor = Exception.class)
    public void createOrder() {
        stockApi.reduceStock("PC100",5);
        OrderPO order = new OrderPO();
        // 随机或随意赋值示例
        order.setId(12345);
        order.setOrderSn("ORDER20230401001");
        order.setUserId("USER123456");
        order.setProductCode("PC100");
        order.setCount(5);
        order.setTotalMoney(100);
        orderMapper.insert(order);
        cartApi.delCart("UU100","PC100");
    }
}
